0% found this document useful (0 votes)
47 views

Computer For ABE

The document contains code for several Arduino sketches that use sensors and actuators. The first sketch calculates the volume of a sphere given its diameter input from the serial monitor. The second sketch blinks LEDs with different timing. Subsequent sketches control an LED with a push button, toggle an LED with a button press, read a potentiometer and display the voltage on an LCD, detect sound with a sensor and light an LED, and monitor water level with a sensor and display it on an LCD.

Uploaded by

Lyka Mae Mancol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Computer For ABE

The document contains code for several Arduino sketches that use sensors and actuators. The first sketch calculates the volume of a sphere given its diameter input from the serial monitor. The second sketch blinks LEDs with different timing. Subsequent sketches control an LED with a push button, toggle an LED with a button press, read a potentiometer and display the voltage on an LCD, detect sound with a sensor and light an LED, and monitor water level with a sensor and display it on an LCD.

Uploaded by

Lyka Mae Mancol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

int pi=3.

14;

String msg1="Diameter of sphere?";

String msg2="Volume=";

String msg3="Diameter=";

float Diameter;

float Volume;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

void loop() {

// put your main code here, to run repeatedly:

Serial.println (msg1);

while (Serial.available()==0){;

Diameter=Serial.parseFloat();

Volume=(4.0/3.0)*3.14*((Diameter/2)*(Diameter/2)*(Diameter/2));

Serial.print (msg3);

Serial.println (Diameter);

Serial.println (msg2);

Serial.println (Volume);

Serial.println ();

}
CODE 2

int L;

int redBlink=5;

int yellowBlink=10;

int greenBlink=15;

int dt = 400;

int redLED=9;

int yellowLED=18;

int greenLED=27;

void setup() {

// put your setup code here, to run once:

pinMode(redLED,OUTPUT);

pinMode(yellowLED, OUTPUT);

pinMode(greenLED, OUTPUT);

void loop() {

// put your main code here, to run repeatedly:

for (L=0; L<redBlink; l++) {

digitalWrite (redLED,HIGH);

delay (dt);

for (L=0; L<yellowBlink; l++) {

digitalWrite (yellowLED,HIGH);

delay (dt);

for (L=0; L<greenBlink; l++) {

digitalWrite (greenLED, HIGH);

delay (dt);
while Serial.available ();

PUSH BUTTON

int redLED = 7;

int buttonPin = 8;

int buttonRead;

int dt = 250;

void setup() {

// put your setup code here, to run once:

pinMode (redLED, OUTPUT);

digitalWrite (buttonPin, INPUT);

Serial.begin (9600);

void loop() {

// put your main code here, to run repeatedly:

buttonRead = digitalRead(buttonPin);

Serial.println (buttonRead);

delay(dt);

if (buttonRead == 0){

digitalWrite (redLED, HIGH);

if (buttonRead ==1){

digitalWrite (redLED, LOW);

int redLED = 7;

int buttonPin = 8;
int LEDstate = 0;

int buttonNew;

int buttonOld = 1;

int dt = 250;

void setup() {

// put your setup code here, to run once:

pinMode (redLED, OUTPUT);

digitalWrite (buttonPin, INPUT);

Serial.begin (9600);

void loop() {

// put your main code here, to run repeatedly:

buttonNew = digitalRead (buttonPin);

Serial.println (buttonNew);

if (buttonOld == 0 && buttonNew == 1){

if (LEDstate == 0){

digitalWrite (redLED, HIGH);

LEDstate = 1;

else{

digitalWrite (redLED, LOW);

LEDstate = 0;

buttonOld = buttonNew;

delay (dt);

}
POTENTIOMETER AND LCD

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,16,2);

int pot = A0;

int potVal;

float Volt;

int dt = 100;

void setup() {

// put your setup code here, to run once:

pinMode (pot,INPUT);

Serial.begin(9600);

lcd.begin (16,2);

void loop() {

// put your main code here, to run repeatedly:

potVal = analogRead(pot);

Volt = (5./1023.)*potVal;

Serial.println (Volt);

delay (dt);

lcd.init ();

lcd.backlight ();

if (Volt >4.0){

lcd.setCursor (4,0);

lcd.print ("Danger!!!");

lcd.setCursor (2,1);

lcd.print("High Voltage!");

}
else if (Volt < 2.5){

lcd.setCursor (6,0);

lcd.print ("Safe!");

lcd.setCursor (2,1);

lcd.print("Continue Ops");

else {

lcd.setCursor (2,0);

lcd.print ("Warning!");

lcd.setCursor (2,1);

lcd.print("Attention!!!");

SOUND SENSOR

int sensor = A0;

int sound;

int dt = 100;

int threshold = 70;

int redLED = 7;

void setup() {

// put your setup code here, to run once:

pinMode (sensor, INPUT);

pinMode (redLED, OUTPUT);

Serial.begin (9600);

void loop() {

// put your main code here, to run repeatedly:


sound = analogRead (sensor);

Serial.println(sound);

if (sound > threshold){

digitalWrite (redLED, HIGH);

else {

digitalWrite (redLED, LOW);

WATER SENSOR

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

LiquidCrystal_I2C lcd = LiquidCrystal_I2C (0x27,16,2);

int watersensor = A0;

int waterVal;

int dt = 100;

void setup() {

// put your setup code here, to run once:

pinMode (watersensor, INPUT);

Serial.begin (9600);

lcd.begin (16,2);

void loop() {

// put your main code here, to run repeatedly:

waterVal = analogRead (watersensor);

Serial.println (waterVal);

delay (dt);

lcd.init ();
lcd.backlight ();

lcd.print ("Water Level:");

if (waterVal < 50.0){

lcd.setCursor (0.1);

lcd.print ("Empty");

else if (waterVal < 150.0){

lcd.setCursor (0.1);

lcd.print ("LOW");

else if (waterVal < 300.0){

lcd.setCursor (0.1);

lcd.print ("MEDIUM");

else if (waterval < 400.0){

lcd.setCursor (0.1);

lcd.print ("HIGH");

else {

lcd.setCursor (0.1);

lcd.print ("FULL");

You might also like