uncategorized

Week 13- Output Devices

This week is about output devices, thing which give out some recognizable output. Neil in his videos explained a variety of them, you can view it here. I have worked with some standard modules available for modular board like arduino. Really excited to make something of my own.
After thorough thinking, i have decided to make the relay circuit needed for my final project. I have a spare 250v 6A, 5V SPDT relay with me. So decided to make a control circuit and a drive circuit for the same.

About Relay

Relay is an electrically activated switch ie, it can be switched ON and OFF using just electric signals. I have a Single Pole Double Throw or simply SPDT relay. It has five terminals one common pin one normally closed (NO) pin, one Normally Closed (NC) pin and one pin for giving the control pulse and one ground pin. The common pin and the NC will be closed when idle, but when a pulse is given across the coil it will become open and the NC and common pin become close. So we should make the connections accordingly.SPDT relays

The design

Rather than driving the mechanical relay directly from the microcontroller i will have a driving circuit for the same. For final project i will be using a Atmega 328p microcontoller and it would be hard to drive the relay directly by it. I have planned to have the final project done in modular ie, I will have a controller board, a board for wifi connectivity, relay board etc. So here is what i have designed for the relay board. It has an npn transistor biased in the switching mode with the coil of the relay connected to the collector terminal.
Relay design
The schematic represenation in eagle is Relay schematic in eagle
The board layed out in eage is Relay board layout

On can can observe that pads are left for th controller to communicate with the relay. It is good for switching AC loads up-to 250V, and that is exactly what I need.

The finished relay board Relay Circuit for final project

I have designed a separate controller board for operating the relay. As I mentioned before, relay is part of my final project and there I have separate controller and wifi boards. Here is the schematic of my controller board and the code is written for switching the relay when ‘ON’ command is received wirelessly through wifi.

Control circuit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>

char ssid[] = "abcd"; // your network SSID (name)
char pass[] = "*****"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's statu

unsigned int localPort = 5000; // local port to listen on

char packetBuffer[255]; // buffer to hold incoming packet
char ReplyBuffer[] = "yuppee"; // a string to send back

WiFiEspUDP Udp;

void setup() {

Serial.begin(9600);
WiFi.init(&Serial);

while ( status != WL_CONNECTED) {
Serial.write("AT+CWMODE=1");
delay(500);
status = WiFi.begin(ssid, pass);
}

Udp.begin(localPort);
pinMode (7, OUTPUT); //relay
pinMode (8, OUTPUT); //LED
}

void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {

// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}
if (strcmp (packetBuffer, "ON") == 0){
digitalWrite(7, HIGH); //to relay
digitalWrite(8, HIGH); //to LED
}
else if (strcmp (packetBuffer, "OFF") == 0){
digitalWrite(7, LOW); //to relay
digitalWrite(8, LOW); //to LED
}

// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}

You can see that pin 7 is connected to the relay. VCC and GND are also passed on to the relay circuit.

Controller plus relay

Parallel Attempt

The weeks assignment has been put into a project for detecting hypothermia during neonatal care. I came across the wonderful product by “Bempu” which is my inspiration for doing this project. I will try to make a similar one with the materials available in our lab.

Aim

To make the device with the following

  1. A thermistor for monitoring the temperature.
  2. An LED to indicate the status. Will blink with varying speeds according to the situation.
  3. To have a battery strapped to it for power.
  4. Molding and casting for making the body of the watch.
  5. Probably some reinforcement while making the bracelet.

Input and output side

We have thermistors, both NTC and PTC, , and I chose NTC. Keeping Neils hello.temp as reference I made a board which has the mechanism to sense and monitor temperature. I also added an led for the time being as an indicator. The LED will blink rapidly when the temperature goes below a certain level.

schematic
"My temp sensing board."

In the final stage I am going to add a buzzer along with the LED which could give out a alarm beep when necessary.

The logic part

Thermistor is something that changes resistance with change in temperature. With NTC the resistance drops with increase in temperature. the math d says the relation between the change in temperature and change in resistance in non-linear but exponential. There are different equations and chose the Beta equation which is as follows

betaEq

So from the data sheet of the thermistor I am using I can get all the necessary values of the constants that comes in the equation. Here R(25) = 10000 & B(25/85) = 3750.

We have the thermistor at one of the branches of a bridge circuit. The ADC’s are connected to the bridge to monitor the voltage fluctuations.

The board is inspired from hello.temp, and the AVR-C code is derivative of Neil’s coode for the same. I have changed the purpose of the board from sending the data to the computer through FTDI to blinking an LED when the temperature is below 25C ,which is the critical low temp of for hypothermia. I have included the processing of the ADC output in the chip itself enabling it to function independently. Apart from that I have changed the ADC from bipolar differential, as in the original code, to unipolar differential code. Here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// hello.temp.45.c
//
// thermistor hello-world
// 9600 baud FTDI interface
//
// Neil Gershenfeld
// 10/27/10
//
// Modified by Vishnu Easwaran 12/06/2016 for Fab Academy 2016
//
//
// (c) Massachusetts Institute of Technology 2010
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose. Copyright is
// retained and must be preserved. The work is provided
// as is; no warranty is provided, and users accept all
// liability.
//

#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <math.h>

#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define char_delay() _delay_ms(10) // char delay


int main(void) {
//
// main
//
DDRB = 0b0001;
//
// set clock divider to /1
//
CLKPR = (1 << CLKPCE);
CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
//
// init A/D
//
ADMUX = (0 << REFS2) | (0 << REFS1) | (0 << REFS0) // VCC ref
| (0 << ADLAR) // right adjust
| (0 << MUX3) | (1 << MUX2) | (1 << MUX1) | (1 << MUX0); // 20(PB4-PB3)
ADCSRA = (1 << ADEN) // enable
| (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // prescaler /128
//
// main loop
//
while (1) {
//
// initiate conversion
//
ADCSRA |= (1 << ADSC);
//
// wait for completion
//
long int b, HSB, LSB;
while (ADCSRA & (1 << ADSC));
//
// get result
//
b = ADCL; // get LSB
char_delay();
//
// converting LSB to decimal
//
int dec=0,i=0,d;
while(b!=0)
{ d = b%10;
dec=dec+d*pow(2,i);
b=b/10;
i++;
}
LSB = dec;
dec=0;i=0;

b = ADCH; // get the MSB
char_delay();
//
// converting HSB to decimal
//
while(b!=0)
{ d = b%10;
dec=dec+d*pow(2,i);
b=b/10;
i++;
}
HSB = dec;
dec=0;
//
// taking decision based on the temperature
//
double V, R, B, R25, T;
double value = 256*HSB+LSB;
V = 2.5 - value*5.0/(20.0*512.0);
R = 10000.0/(5.0/V-1.2);
B = 3750.0;
R25 = 10000.0;
T = 1.0/(log(R/R25)/B+(1/(25.0+273.15))) - 273.15; //calculating temp

if (T < 25.0){
PORTB = 0b00001; // turn the LED on
_delay_ms(500); // for blnking
PORTB = 0b00000; // for blinking
_delay_ms(1000); // for blinking

}
else{
PORTB = 0b00000; // have the LED of
}
}
}


Your browser does not support the video tag.

Work to be done

  • in place of the LED have a buzzer to sound alarm.
  • make a bracelet, probably mold or cast, which can hold the sensor.

Design files of this week

Share