A sensor is a device that detects changes and events in a physical stimulus and provides a corresponding output signal that can be measured and/or recorded. Here, the output signal can be any measurable signal and is generally an electrical quantity.
An analog sensor produces continuously varying output signals over a range of values. Usually the output signal is voltage and this output signal is proportional to the measurand. The quantity that is being measured like speed, temperature, pressure, strain, etc. are all continuous in nature and hence they are analogue quantities A thermocouple or a thermometer is an analog sensor. The following setup is used to measure the temperature of the liquid in the container using a thermocouple.
A digital sensor produces discrete digital signals. The output of a digital sensor has only two states, namely ‘ON’ and ‘OFF’. ON is logic 1 and OFF is logic 0. A push button switch is the best example of a digital sensor. In this case, the switch has only two possible states: either it is ON when pushed or it is OFF when released or not pushed. The following setup uses a light sensor to measure the speed and produces a digital signal.
Actuators are devices that work opposite to sensors. A sensor converts a physical event into an electrical signal, whereas an actuator converts electrical signal into a physical event. When sensors are used at input of a system, actuators are used to perform output function in a system as they control an external device.
Transducers are the devices that convert energy in one form into another form. Generally the energy is in the form of a signal. Transducer is a term collectively used for both sensors and actuators.
Source :For this assignment a board was developed which is responsible for capturing an analog signal by means of the LDR sensor by which we can perceive variations of light. To accomplish this, an attiny 45 with a pin with analog input will be used to capture the voltage variation of the sensor.
The Light Dependent Resistor (LDR) is just another special type of Resistor and hence has no polarity. Meaning they can be connected in any direction. They are breadboard friendly and can be easily used on a perf board also. The symbol for LDR is just as similar to Resistor but adds to inward arrows . The arrows indicate the light signals. A photoresistor or LDR (Light Dependent Resistor), as the name suggests will change it resistance based on the light around it. That is when the resistor is placed in a dark room it will have a resistance of few Mega ohms and as we gradually impose light over the sensor its resistance will start to decrease from Mega Ohms to few Ohms.
In the datasheet we can find the information on all the pins that the micorcontroller has and if they are analog or digital in this compose we have 3 analog and 6 digital. to be able to control the LDR sensor with the microcontroller we will need an analog pin and to be able to verify this we will use a led connected to a digital pin which will turn on and off based on the light capture of the LDR.
int analogPin = 3; //pin 2 int LEDPin = 1; //pin 6 int val = 0; void setup() { pinMode(LEDPin, OUTPUT); digitalWrite(LEDPin,LOW); delay(2000); digitalWrite(LEDPin,HIGH); } void loop() { val = analogRead(analogPin); // read the input pin if(val < 200) { digitalWrite(LEDPin,LOW); delay(2000); } else { digitalWrite(LEDPin,HIGH); } }
Heree is the video for same.
The HC-SR04 ultrasonic sensor uses SONAR to determine the distance of an object just like the bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package from 2 cm to 400 cm or 1” to 13 feet.
The operation is not affected by sunlight or black material, although acoustically, soft materials like cloth can be difficult to detect. It comes complete with ultrasonic transmitter and receiver module.I tried simulation on Arduino with Ultrasonic Sensor
#define trigPin 13 #define echoPin 12 #define led 11 void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(led, OUTPUT); } void loop() { long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 10) { digitalWrite(led,HIGH); } else { digitalWrite(led,LOW); } Serial.print(distance); Serial.println(" cm"); delay(500); }
As Attiny does not have serial communication abilities.So i edit the code and remove timing and serial communication protocal.Now it showed the led.
#define trigPin 2 #define echoPin 1 #define led 3 void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(led, OUTPUT); } void loop() { long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 10) { digitalWrite(led,HIGH); } else { digitalWrite(led,LOW); } delay(500); }
These are the initial design which I made first and milled it also but there are so many missing connection was there.
In schematic I connected both the pins but in board they does not come out, While giving labelling it is important to check they are connected or not by using ERC command.So in this case MOSI and SCK are not connected thats why I was not able to program it.
As we have to complete final project first ,I started work on final project Electronics Design and then I used Attiny 44 for LDR as input and Servo Motor as output.The schematic and Board for this You can check in Week 12 Output Devices as with this board , I dint work on input devices.
I also design this board on Attiny 44 but when I uploaded the whole program of 4 LDR inputs and 2 servo motor. The memory of attiny was almost full.I also cant see the data of serial monitor with that then I moved to Atmega 328P.
Here you can see the Schematic of ATmega328p.
As per shatshakit I implement my design on it.For burning bootloder I gave 16 MHz oscillator and two 22uf capacitors and also pins for AVRISP(MISO MOSI RST GND VCC SCK).After Voltage Regulator, I gave diode so that current does not come back again to it.
These are the PNG traces exported to go to milling process.
The process for PCB Milling was explained in Electronic Production week.
Here is the Video showing Milling of Final Baord PCB.
After Milling this is the PCB for Servo Motor and LDR.Everything come out fine except at one point on Atmega traces got shot.I used knife to cut the shot traces.
For soldering, I collect all the components and write it down.Below is the Image showing all the components.
Here is the video for soldering
After soldering the PCB is here.
This is the backside of PCB.
#include "SoftwareSerial.h"
#define RX 4 //TX pin of ATmega
#define TX 3 //RX pin of ATmega
SoftwareSerial mySerial(4,3); //RX, TX
int sensorPin = A5; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
mySerial.begin(9600); //sets serial port for communication
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
mySerial.println(sensorValue); //prints the values coming from the sensor on the screen
delay(1000);
}
For this I have used SDA and SCL ie A4 and A5 pin of ATmega for I2C communication.
In case of Attiny 44 it does not support library for ds3231 RTC, I was not able to program pcb of Attiny44.
#include "Wire.h"
#include "RTClib.h"
#include "SoftwareSerial.h"
#define RX 4 //TX pin of ATmega
#define TX 3 //RX pin of ATmega
SoftwareSerial mySerial(4,3); //RX, TX
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup ()
{
mySerial.begin(9600);
delay(3000); // wait for console opening
if (! rtc.begin()) {
mySerial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
mySerial.println("RTC lost power, lets set the time!");
// Comment out below lines once you set the date & time.
// Following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// Following line sets the RTC with an explicit date & time
// for example to set January 27 2017 at 12:56 you would call:
// rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
}
}
void loop ()
{
DateTime now = rtc.now();
mySerial.println("Current Date & Time: ");
mySerial.print(now.year(), DEC);
mySerial.print('/');
mySerial.print(now.month(), DEC);
mySerial.print('/');
mySerial.print(now.day(), DEC);
mySerial.print(" (");
mySerial.print(daysOfTheWeek[now.dayOfTheWeek()]);
mySerial.print(") ");
mySerial.print(now.hour(), DEC);
mySerial.print(':');
mySerial.print(now.minute(), DEC);
mySerial.print(':');
mySerial.print(now.second(), DEC);
mySerial.println();
mySerial.println("Unix Time: ");
mySerial.print("elapsed ");
mySerial.print(now.unixtime());
mySerial.print(" seconds/");
mySerial.print(now.unixtime() / 86400L);
mySerial.println(" days since 1/1/1970");
// calculate a date which is 7 days & 30 seconds into the future
DateTime future (now + TimeSpan(7,0,0,30));
mySerial.println("Future Date & Time (Now + 7days & 30s): ");
mySerial.print(future.year(), DEC);
mySerial.print('/');
mySerial.print(future.month(), DEC);
mySerial.print('/');
mySerial.print(future.day(), DEC);
mySerial.print(' ');
mySerial.print(future.hour(), DEC);
mySerial.print(':');
mySerial.print(future.minute(), DEC);
mySerial.print(':');
mySerial.print(future.second(), DEC);
mySerial.println();
mySerial.println();
delay(1000);
}
We measured the analog signal by connecting both the probe of oscilloscope to Gnd and Vcc pin of dc motor and rotated the shaft manually. The motor is generally consisdered as the output device but if we give rotation to motor manually then an induced voltage can be seen on the oscilloscope. Since the construction of the motor and generator are similar so we used motor as the input device.
We uploaded Blink code on the UNO board and we observed the pulse signal.Above are the results for the same.