Program 1.
a - Siren light
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(13, HIGH);
delay(200); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
delay(200);
digitalWrite(12, LOW);
}
Siren Light
Program 1.b - Siren buzzer
void setup()
{
}
void loop()
{
digitalWrite(9, HIGH);
tone(9, 440 * pow(2.0, (constrain(int(map(300, 0, 1023, 36, 84)), 35, 127) - 57) / 12.0), 1000);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(9, LOW);
tone(9, 440 * pow(2.0, (constrain(int(map(200, 0, 1023, 36, 84)), 35, 127) - 57) / 12.0), 1000);
}
Siren Buzzer
Program 1.c- Siren light buzzer assessment
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(13, HIGH);
tone(9, 440 * pow(2.0, (constrain(int(map(300, 0, 1023, 36, 84)), 35, 127) - 57) / 12.0), 1000);
delay(200); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
// Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
tone(9, 440 * pow(2.0, (constrain(int(map(200, 0, 1023, 36, 84)), 35, 127) - 57) / 12.0), 1000);
delay(200);
digitalWrite(12, LOW);
//delay(100);
}
Siren light buzzer assessment
Program 2 - Print “hello world” to Arduino Serial Monitor.
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print("Hello World");
delay(1000);
}
Circuit design Program2 | Tinkercad
Program 3 - Display of addition of two random numbers in Arduino Serial Monitor.
int z;int a;int b;
void setup()
{
Serial.begin(9600);
}
void loop()
{
a = random(100);
b = random(100);
z = calculate(a,b);
//Adding 2 Numbers
//Write Values to Serial Monitor
Serial.print(a);
Serial.print(" + ");
Serial.print(b);
Serial.print(" = ");
Serial.println(z);
delay(1000);
}
float calculate(int x, int y)
{
return (x + y);
}
Circuit design Program3 | Tinkercad
Program 4 - Push Button for changing LED state.
#define LED_PIN 8
#define BUTTON_PIN 7
byte lastButtonState = LOW;
byte ledState = LOW;
void setup()
{
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
void loop()
{
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastButtonState = buttonState;
if (buttonState == LOW) {
ledState = (ledState == HIGH) ? LOW: HIGH;
digitalWrite(LED_PIN, ledState);
}
}
}
https://www.tinkercad.com/things/7EShjOz7FMF-mighty-robo/editel?tenant=circuits
Program 5 - Controlling LED Blinks with variable resistance.
int potPin = 2; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop()
{
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
}
Program 6 - Dimmer.
const int ledPin = 9; // the pin that the LED is attached to
void setup() {
// initialize the serial communication:
Serial.begin(9600); // initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness; // check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read(); // set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
Program 7 - LCD Display
#include <LiquidCrystal.h>
//#include <Adafruit_LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Adafruit_LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
String s1="NAMASTE EVERYONE!!!!!!", s3="WELCOME TO ARDUINO WORKSHOP";
int i,j,k;
void setup() {
String s2="",s4="",s5="";
// set up the LCD's number of columns and rows:
lcd.clear();
lcd.begin(16, 2);
// Print a message to the LCD.
for(i=0;i<=s1.length();i++){
s2+=s1[i];
lcd.print(s2);
delay(300);
lcd.clear();
for(i=0;i<=s1.length();i++){
lcd.clear();
s2="";
for(j=i;j<s1.length();j++){
s2+=s1[j];
}
lcd.print(s2);
delay(300);
}
lcd.clear();
lcd.print(s3);
delay(800);
// Print a message to the LCD.
for(k=0;k<3;k++){
for(i=0;i<=s3.length();i++){
lcd.clear();
s2="";
for(j=i;j<s3.length();j++){
s2+=s3[j];
}
lcd.print(s2);
delay(300);
}
}
setup();
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
// lcd.print(millis() / 1000);
}
Circuit design Sizzling Fulffy-Rottis | Tinkercad
Program 8 - Read temperature from thermistor.
void setup() {
//This function gets called when the Arduino starts
Serial.begin(115200);
//This code sets up the Serial port at 115200 baud rate
}
void loop() {
//This function loops while the arduino is powered
int val; //Create an integer variable
val=analogRead(0);
//Read the analog port 0 and store the value in val
Serial.println(val);
//Print the value to the serial port
delay(1000);
//Wait one second before we do it again
}
Circuit design Brilliant Habbi-Lappi | Tinkercad
Program 9 - Disco Lights
int timer = 100; // The higher the number, the slower the timing.
int pins[] = { 2, 3, 4, 5, 6, 7 ,8,9,10,11}; // an array of pin number
int num_pins = 10; // the number of pins (i.e. the length of the array)
void setup()
{
int i;
for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output
}
void loop() {
int i;
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
digitalWrite(pins[num_pins-i-1], HIGH);
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // and turning it off.
digitalWrite(pins[num_pins-i-1], LOW);
} for (i = num_pins - 1; i >= 0; i--)
{
digitalWrite(pins[i], HIGH);
digitalWrite(pins[num_pins-i-1], HIGH);
delay(timer);
digitalWrite(pins[i], LOW);
digitalWrite(pins[num_pins-i-1], LOW);
}
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
digitalWrite(pins[(i+2)%10], HIGH);
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // and turning it off.
digitalWrite(pins[(i+2)%10], LOW);
}
for (i = num_pins - 1; i >= 0; i--)
{
digitalWrite(pins[i], HIGH);
digitalWrite(pins[(i+2)%10], HIGH);
delay(timer);
digitalWrite(pins[i], LOW);
digitalWrite(pins[(i+2)%10], LOW);
}
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
digitalWrite(pins[(i+3)%10], HIGH);
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // and turning it off.
digitalWrite(pins[(i+3)%10], LOW);
}
for (i = num_pins - 1; i >= 0; i--)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
digitalWrite(pins[(i+3)%10], HIGH);
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // and turning it off.
digitalWrite(pins[(i+3)%10], LOW);
}
for (i = 0; i < num_pins; i++)
{ // loop through each pin...
digitalWrite(pins[i], HIGH); // turning it on,
digitalWrite(pins[(num_pins/2+i)%10], HIGH);
delay(timer); // pausing,
digitalWrite(pins[i], LOW); // and turning it off.
digitalWrite(pins[(num_pins/2+i)%10], LOW);
}