Posts with «gui» label

Arduino python GUI led control

Hello Friends,

In this project, we are interfacing arduino with python. Arduino can be easily interfaced with python using serial communication (uart) via pyserial library. For GUI on python, we are using tkinter.

Let's start with the python script:
Libraries required: pyserial

It can  be esaily installed by: pip install pyserial




Python script:

import serial as s
import time as t
from tkinter import *
from tkinter import messagebox


ser = s.Serial('COM3', 9600, timeout=0)   # check your com port
t.sleep(2)

def on():
    ser.write(b'7')

def off():
    ser.write(b'8')

def exit():
    ser.close() # close serial port
    quit()

window = Tk()
window.title("                  ARDUINO MEETS PYTHON")
window.geometry('640x480')
lbl = Label(window, text="Welcome to this project",fg='black',font=(None, 15))
lbl.place(relx=0.30, rely=0.10, height=50, width=250)
bo = Button(window, text="LED ON", width=10 ,bg='red' ,command=on)
bo.place(relx=0.34, rely=0.30, height=40, width=200)
cb = Button(window, text="LED OFF", width=10, bg='green' ,command=off)
cb.place(relx=0.34, rely=0.40, height=40, width=200)
ext = Button(window, text="Exit", width=10, bg='white', command=exit)
ext.place(relx=0.34, rely=0.50, height=40, width=200)
window.mainloop()

 Arduino code:

char a=0;
const int led=13;

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
lcd.init();
lcd.backlight();
}

void loop() {
if(Serial.available()>0)
a=Serial.read();

lcd.setCursor(3,0);
lcd.print(a,DEC);

if(a=='7')
{
  digitalWrite(led,HIGH);
}
else
{
  digitalWrite(led,LOW);
}

}

////// code ends here

Note: LCD is optional

Python GUI
Video:


Arduino and processing based GUI person counter

In this post, we will make arduino and processing based GUI person counter. For person counter, we are using infrared sensor (IR). It's output is digital and is fed to pin number 7 of arduino.

The connections are as follows:


Arduino Code:

int switchPin=7;
int ledPin=13;

void setup() {
pinMode(switchPin,INPUT);
digitalWrite(switchPin,HIGH);
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}

void loop() {
  if(digitalRead(switchPin))
    {
    while(digitalRead(switchPin));        
    Serial.print(1,DEC);
    }
  else
    {
    Serial.print(0,DEC);
    }
    delay(100);
} 

Processing Code:

import processing.serial.*;

Serial port;
int val;
int count=0;
PFont f;                           // STEP 1 Declare PFont variable

void setup()  {
    size(400,400);
    noStroke();
    println(Serial.list());  // print list of available serial port 
    port=new Serial(this,Serial.list()[0],9600);        
    f = createFont("Arial",16,true); // STEP 2 Create Font
 }
  
void draw()  {
  if(0<port.available())
  {
    val=port.read();
  } 
    background(204);
    println(val);

  if(val==48)
{     fill(255,0,0);   // red
  rect(50,50,300,300);  // green
}
  else if(val==49)
{     fill(0,255,0);   // green
  rect(50,50,300,300);  // green
  count++;
}

  textFont(f,30);               
  fill(0);                         
  text("Number of Person is: " + count , 30, 30);
//text(count, 100, 100);
delay(100);

 }

/* END OF CODE */

Temperature on GUI using visual studio and arduino

In this post, first we will interface LM35 with arduino uno and then  upload this data through serial communication. With the help of visual studio we can make computer gui application and though this gui application, we can do lot of stuffs like temperature logger, humidity monitoring. The

Stuff we require:

  1. Arduino uno with usb cable
  2. LM35
  3. Jumper wires
  4. Visual Studio (I had used VS 2012)
Make connections as follows:

LM35 interfacing with arduino


Simply provide, Vcc and GND to temperature sensor (LM35) and it's output should be connected to A0 of arduino. You can connect it to any channel from A0 to A5.

Calculation part:

There is little bit calculation. LM35 gives analog output. It's linearity is 10 mV/°C
which literally means for rise in temperature of 1°C, there be an increment of mV from output of lm35. It's graph is linear. It's temperature range is from: -55°C to +150°C.
Since, we are using LM35 it is calibrated in terms of degree celsius. There are other variants available like lm235 and lm335.

Arduino Code: 

The code is very simple

/*
Code Starts
*/


float val=0.0;

void setup() {
Serial.begin(9600);
}

void loop() 
{
val=analogRead(A0);
val=(0.4887*val);
Serial.println("VALUE OF TEMPERATURE IS: " + String(val) );
delay(1500);
}

/*
Code Ends
*/

Check out the video:


Visit this blog for more updates !!