2.Group Assignment: measure the power consumption of an output device
3.Individual Assignment:
Files:
Planning:Tools:
#include Servo.h Servo myservo; int pos = 0; void setup() { myservo.attach(0); // PWM pin PB0 } void loop() { for (pos = 0; pos <= 160; pos += 2) { myservo.write(pos); delay(80); } for (pos = 160; pos >= 0; pos -= 2) { myservo.write(pos); delay(80); } }
I programmed my microntroller using UPDI pin, with the help of megaTinyCore library, and I used UPDI + VCC module.
To control a servo, we need a GND, VCC, and a Analog Pin. Maximum Voltage of my servo is 6v.
#include
Servo servo;
int pos = 0;
int pin = 1;
void setup() {
servo.attach(pin);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
servo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
servo.write(pos);
delay(15);
}
}
Connect Servo Pin to PA7 Pin, which maps to Arduino "1".
The LCD 2004A can be controlled by either I2C or SPI, I chose I2C. Therefore, we need 2 more pins apart from SCL and SDA. LCD 2004A needs 5v-10v. It has 4 rows, and 20 columns.
#include // Library for I2C communication
#include // Library for LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Wire.begin();
lcd.init();
lcd.backlight();
}
void loop() {
lcd.clear();
lcd.home();
lcd.print("Regression");
lcd.setCursor(2, 1);
lcd.print("To The Mean");
lcd.setCursor(0, 2);
lcd.print("fabacademy2021");
lcd.setCursor(9 ,3);
lcd.print("->Jai Hanani");
delay(200);
}
Native Arduino LiquidCrystal Library, and there you can find the documentation for all the commands I used in the code.
For the group assignment, we used our colleague's output devices board to measure its power. The following code was used to see the difference in current and then calculate the power consumption of both the connected servo and buzzer.
#include
#define buzz 4
Servo myservo;
int angle = 0;
void setup() {
pinMode(buzz, OUTPUT);
myservo.attach(0);
}
void loop() {
for (angle = 0; angle <= 180; angle += 1) {
myservo.write(angle);
delay(20);
}
delay(100);
for ( angle = 180; angle >= 0; angle -= 1) {
myservo.write(angle);
delay(20);
}
digitalWrite(buzz, 1);
delay(2000);
digitalWrite(buzz, 0);
delay(2000);
}
No Output Connected ==> Voltage = 5V; Current = 0.011A
Only Buzzer Connected ==> Voltage = 5V; Current = 0.05475A; Diff. in Current = 0.04375A; Power = V * I = 0.219W
Only Servo Connected ==> Voltage = 5V; Current = 0.71275A; Diff. in Current = 0.70175A; Power = V * I = 3.501W