For this week we have two assignments, one individual and a group assignment.
Individual: Add an output device to a microcontroller board you have designed. And program it to do something.
Group Assignment: Measure the power consumption of an output device.
Group Assignment
The assignment for this week was to measure the power consumption of an output device. So what we did was to connect a multimeter to measure the power consumptions of a stepper motor while in motion.
Measuring Power Consumption
In order to measure power consumption of a device whilst using Arduino, we have to follow the steps below:
Select the milliamp range on the meter
Connect the red lead to the meter's milliamp socket
Disconnect the power supply from the board
Connect the GND of the supply connector to the GND of the board connector
Connect the red probe of the meter to the positive connector on the supply
Connect the black probe of the meter to the positive connector on the board
Observe the meter reading
Multiply milliamps/1000 by voltage to get power in watts
Voltage measured with second meter
rated voltage of supply
voltage measured earlier or later
Power Consumption of a Stepper Motor
The stepper motor was set on continuous motion, and the power consumption was measured. Below, you can see the results:
For the full group project click on the following link:
As for the individual assignment, I decided to do something related to my project which would include two crash sensors (shown in previous week as inputs) which would in turn control two relay modules that would activate water pumps. Since the relay module is relatively simple, I decided to also include a few components for this week's experimentations shown in below:
First the relay module. This one in specific has four relays and needs 6 pins, 2 for VCC and GND and the rest to receive signal for each relay. Relays are usefull for safety measures as well as being able to channel different voltages.
The second is a Servo SG-50. This one has 3 pins, VCC, GND and signal.
Lastly I used a laser module which also has 3 pins, VCC, GND and Signal.
Since I used the Inputs week to produce my PCB, I took into account the addition of outputs to be used in this week and as a prototype for my final project. Below are videos of the experiments done to showcase the stated modules/components and the codes used.
Relay module
Video:
Code:
int inputPin1 = 8;
int inputPin2 = 5;
int RelayPin1 = 10;
int RelayPin2 = 9;
void setup() {
Serial.begin(9600);
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
}
void loop() {
int val = digitalRead(inputPin1);
if (val == HIGH) {
digitalWrite (RelayPin1, HIGH);
Serial.println("Switch 1 pressed");
Serial.println("Relay 1 Active 3 sec");
delay(3000);
}
int val1 = digitalRead(inputPin2);
if (val1 == HIGH) {
digitalWrite(RelayPin2, HIGH);
Serial.println("Switch 2 pressed");
Serial.println("Relay 2 Active 3 sec");
delay(3000);
}
}
Servo:
Video:
Code:
#include
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Laser Module
Video:
Code:
int laserPin = 9;
int inputPin = 5;
void setup ()
{
Serial.begin(9600);
pinMode (laserPin, OUTPUT);
pinMode (inputPin, INPUT);
}
void loop () {
int val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(laserPin, LOW);
} else {
digitalWrite(laserPin, HIGH);
Serial.println("Laser ON");
delay (3000);
}
}