Arduino Uno Example Projects for Students: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
Line 193: Line 193:


</syntaxhighlight>
</syntaxhighlight>
== Arduino Code Example of Operation using Serial Monitor ==
[[File:Screenshot 2023-05-05 at 5.39.08 am.png | 900px]]

Revision as of 19:39, 4 May 2023

Solar Distillation - Water Purification project

Solar Distillation and the production of Drinking Water

  • Solar distillation is a process of purifying water by using the sun's energy to evaporate water and condense the resulting vapor into a clean container. It is a simple, effective and sustainable method of producing safe drinking water, especially in regions where clean water sources are scarce.
  • The process of solar distillation involves the use of a solar still, which is a device that consists of a shallow basin or pit covered with a transparent material such as glass or plastic. The basin is filled with contaminated water, and the sun's rays heat the water, causing it to evaporate. The water vapor then rises and condenses on the cooler surface of the transparent cover, which is angled to allow the condensate to flow into a collection container.
  • To make drinking water using solar distillation, the following steps can be followed:
    • Build or acquire a solar still: A solar still can be made using simple materials such as glass or plastic sheets, wood, and metal. Alternatively, pre-built solar stills can be purchased from manufacturers.
    • Place the solar still in a sunny location: The solar still should be placed in a location where it receives maximum sunlight exposure throughout the day.
    • Fill the still with contaminated water: The contaminated water is poured into the basin of the still.
    • Cover the still with a transparent material: The basin is covered with a transparent material such as glass or plastic, which allows sunlight to enter and heat the water.
    • Wait for the water to evaporate and condense: As the water is heated by the sun, it evaporates and rises to the surface of the transparent cover, where it condenses and drips into a collection container.
    • Collect the clean water: The condensed water that drips into the collection container is clean and safe for drinking.

Overall, solar distillation is a simple and effective method of producing safe drinking water using the sun's energy. It is particularly useful in remote or arid regions where access to clean water is limited.

Solar Distillation using a Solar Thermal Collector Panel

  • In this Solar Distillation experiment a flat panel is used to distill the water.
  • The Solar Distillation panel covered by a black felt mat to maximise heat gain and also slow down the fall of water on the panel.
  • The Panel is also covered by a transparent sheet of plastic drawn taught over the panel, that allows sunlight to pass through, and that also collects droplets of distilled water.
  • Dirty water is pumped to the top of the panel.
  • As the dirty water falls down the length of the panel (by gravity) it heats up and some of the water evaporates.
  • The evaporated water condenses on the inside surface of the clear plastic film of plastic. Once the water droplets ae big enough they will trickle down the inside surface as small rivulets of water.
  • Dirty water is collected at the base of the panel and is returned to the main dirty water tank.
  • Purified water is collected as runoff from the plastic film and is collected in a drinking water tank.

Fritzing Circuit Diagram

  • Parts required:
    • Relay - Pololu Basic SPDT Relay Carrier with 5VDC to control pump. Relay controlled using pin 12 on Arduino. Core Electronics
    • Peristaltic pump - Peristaltic Liquid Pump with Silicone Tubing - 5V to 6V DC Power Core Electronics
    • LED - to indicate status of pump. LED controlled using pin 13 on Arduino.
    • 5V supply - using a Raspberry Pi 3+ Power Supply Core Electronics
    • 5 Amp Fuse - 5A M205 Quick Blow Fuse Jaycar
    • Fuse Holder - Heavy Duty 20A 3AG Inline Fuse Holder (20 Amps, 3AG indicates thickness of leads) Jaycar

Arduino Code Example

  • This code example will demonstrate how to control a peristaltic pump using a relay.
  • After executing the code open the Serial Monitor.
  • To run the pump (turn relay on) enter the command ON and then press the Enter key.
  • To turn the pump off enter the command OFF and then press the Enter key.
  • To understand more about Serial communication from your computer to the Arduino see this Tutorial Arduino Tutorial Serial Inputs
/* Solar Distillation project with Arduino Uno
   Using the Arduino to control a relay (and peristaltic pump). Relay is controlled on Pin 12
   Pump on is signaled using an LED connected to Pin 13
   Relay is turned on and off using commands sent via the Serial Monitor
   ON - turn relay on
   OFF - turn relay off
*/

String command;

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);
  // initialize digital pins as output.
  pinMode(13, OUTPUT); //  LED
  pinMode(12, OUTPUT); // relay
}

// the loop function runs over and over again forever
void loop() {
  delay(500);
  if(Serial.available()){
        command = Serial.readStringUntil('\n');
         
        if(command.equals("ON")){
            digitalWrite(13, HIGH); // turn LED on
            digitalWrite(12, HIGH); // turn relay on
            Serial.println("Relay is now ON");
        }
        else if(command.equals("OFF")){
            digitalWrite(13, LOW); // turn LED off
            digitalWrite(12, LOW); // turn relay off
            Serial.println("Relay is now OFF");
        }
    }
}

Arduino Code - Example of operation

  • After uploading the code (sketch) to the Arduino Uno, click on the Serial Monitor button (top right of Arduino IDE)
  • You can now enter commands from your computer to the Arduino.
  • After a command is entered click Send or press the Enter key.



Solar PV Panel with Servo Scanning

Operation of a Solar PV Panel

A solar photovoltaic (PV) panel works by converting sunlight into direct current (DC) electricity. The panel consists of multiple solar cells made from semiconductor materials, usually silicon, which are connected together.

When sunlight hits the surface of the solar cells, it excites the electrons in the semiconductor material, causing them to move. This movement of electrons creates a flow of electricity, which can be captured by the panel and used to power electrical devices.

The solar cells are arranged in a grid pattern and wired together to form a module. Multiple modules can then be connected together to form a solar panel, which can generate more electricity.

The amount of electricity generated by a solar panel depends on several factors, including the amount of sunlight it receives, the efficiency of the solar cells, and the temperature of the panel. A solar panel typically generates more electricity in direct sunlight and at cooler temperatures.

Any excess electricity produced by a solar panel can be stored in batteries or fed back into the grid for others to use.

What is a Servo Motor and how does it work using Pulse Width Modulation

A servo motor is a type of motor that is used for precise control of position. It is commonly used in robotics, automation, and other applications where precise motion control is needed.

A servo motor works by receiving a control signal that specifies the desired position. The control signal sent to the servo motor is typically a pulse-width modulation (PWM) signal. PWM is a technique used to encode a message into a pulsing signal. In the case of servo motors, the PWM signal encodes the desired position of the servo.

Most hobby servos use a pulse that lasts between 1 millisecond and 2 milliseconds to tell it how much to turn. A 1 millisecond pulse means that the servo shaft is turned all the way to the left, usually called the 0 degree position. A 2 millisecond pulse tells the servo to turn all the way to the right, the 180 degree position. A 1.5 millisecond pulse would send the servo to the neutral or middle position.

Hobby servos have a built-in feedback mechanism, typically in the form of a potentiometer, that provides information on the current position of the motor. The motor adjusts its output shaft until the feedback signal matches the desired position or speed specified by the PWM signal.

In summary, a servo motor works by receiving a PWM control signal that specifies the desired position or speed of the motor. The motor uses the control signal and feedback mechanism to adjust its output shaft to move to the desired position.

Fritzing - Circuit Diagram for Hobby Servo Motor

Arduino Code Example

/*
 Sun Tracker project
 Servo motor with solar PV panel attached
 Will find sunniest location and stay there for 1 minute
 Then will sweep again to find next sunniest position (sun will move during the day)
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
int servoPosition = 0; 
int sunniestServoPosition = 0;
int sunniestSolarValue = 0;
int solarPin = A2;    // select the input pin for the potentiometer
int solarValue = 0;  // variable to store the value coming from the sensor
int count = 0;      // counter 

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
}

void loop() {
    for (servoPosition = 20; servoPosition <= 170; servoPosition += 10) { 
        // servo goes from 0 degrees to 180 degrees - but values 0 and 180 cause servo to gitter
        // so instead the range will be from 20 to 170
       // in steps of 10 degree
       myservo.write(servoPosition);      // tell servo to go to position in variable 'pos'
       Serial.print("The current servo position is ");
       Serial.println(servoPosition);
       delay(200);                       // wait for 0.2 seconds for the servo to reach position
       
       // read the value from the solar PV panel on Analog Pin A2:
       // analog pin returns reads 0-5V by returning a value between 0 and 1023
       solarValue = analogRead(solarPin);
       Serial.print("The solarValue is ");
       Serial.println(solarValue);

       // Check to see if servo has found a new sunniest location
       // If location is sunnier then store this servoPosition value
       if (solarValue > sunniestSolarValue){
         sunniestSolarValue = solarValue;
         sunniestServoPosition = servoPosition;
         Serial.print("We have a new sunniest location! ");
         Serial.println(servoPosition);
       }
    }

    // goto Sunniest Position and wait there for 1 minute
    Serial.print("Going to sunniest position ");
    Serial.print(sunniestServoPosition);
    Serial.println(" for 1 minute ");
    myservo.write(sunniestServoPosition);
    
    // waits in sunniest position for 1 minute
    for (count = 0; count <= 60; count += 10) { 
       Serial.print("Counting to 60 - ");
       Serial.println(count);
       delay(10000); // 10 seconds each loop 
    }                     
}

Arduino Code Example of Operation using Serial Monitor