
Now you might get confuse that which pin is first and which one is last so, So first look at the GPIO pins working in raspberry pi B+ model which is shown in diagram shown below. In this post we are going to see how we can add a temperature sensor to our raspberry pi and sense temperature using python.įrom three pins of temperature sensor one of them should be connected to the ground while the other two are power and data pins. My temperature sensor’s unique id is starting from 28 so i’ve written /28* in /devices to find all my sensors, If yours are starting from some other number than please consider changing it. Now, this file will store your temperature and timestamp into database as well as will give temperature as output. # Sometimes reads fail on the first attempt # get the temperature from the device file # search for a device file that starts with 28ĭevicelist = glob.glob(‘/sys/bus/w1/devices/28*’) # is the status is ok, get the temperature from line 2 Now, we are going to write a python script which will extract temperature data from w1_slave file, divide it by 1000 and store it in sqlite database with the time at which temperature was registered. Fourth will create a table temp which will store date and time of temperature and temperature value.

Third command will tell sqlite to begin taking actions according to commands. After that second command will enter sqlite creating and using temps.db as default database. Here, first command will install sqlite database on your raspberry pi.

CREATE TABLE temp (timestamp DATETIME,temp NUMERIC) So run these set of commands to install and setup your sqlite database.Ĥ.
HOW TO INSTALL SQLITE ON RASPBERRY PI HOW TO
In this post we are going to see how to store temperature into sqlite database. First of all you have to install sqlite into your raspberry pi.
