{"id":106,"date":"2023-12-21T19:27:48","date_gmt":"2023-12-21T19:27:48","guid":{"rendered":"https:\/\/theroyalscode.com\/ehs\/?p=106"},"modified":"2023-12-21T19:27:49","modified_gmt":"2023-12-21T19:27:49","slug":"naughty-or-nice-scanner","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/ehs\/2023\/12\/21\/naughty-or-nice-scanner\/","title":{"rendered":"Naughty or Nice Scanner"},"content":{"rendered":"\n<p>Have you been naughty or nice this year? This is usually a question that torments children and they have to wait until Christmas morning to find the answer. With our state of the art Sant-a-Scanner, we can say with scientific certainty if you are on the naughty or nice list in under a minute! I was really impressed with the work we did. While I helped, my high school students did most of the wiring and coding themselves (Which will be obvious if you look at the code.)<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1080\" style=\"aspect-ratio: 1920 \/ 1080;\" width=\"1920\" controls src=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/1000005877.mp4\"><\/video><\/figure>\n\n\n\n<div class=\"wp-block-media-text is-stacked-on-mobile\" style=\"grid-template-columns:22% auto\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-5-768x1024.png\" alt=\"\" class=\"wp-image-108 size-full\" srcset=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-5-768x1024.png 768w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-5-225x300.png 225w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-5-1152x1536.png 1152w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-5.png 1440w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p><ul> <\/ul>Here is what we used:<\/p>\n\n\n\n<p><ul><li>A Raspberry Pi 3B+ with a power supply, and SD card with a loaded operating system<\/li><li>Ultrasonic Distance Sensor (HC-SR04) with a <a href=\"https:\/\/cults3d.com\/en\/3d-model\/tool\/ultrasonic-sensor-case-hc-sr04-dgemily\">3D printed case<\/a><\/li><li><a href=\"https:\/\/www.adafruit.com\/product\/1138\">4 meter NeoPixel strip <\/a><\/li><li><a href=\"https:\/\/www.amazon.com\/Universal-Adapter-Converter-Inverter-Transformer\/dp\/B09NLMVXMZ\/ref=sr_1_3?keywords=5v%2Bpower%2Bsupply%2B3a&amp;qid=1703170698&amp;sr=8-3&amp;th=1\" data-type=\"link\" data-id=\"https:\/\/www.amazon.com\/Universal-Adapter-Converter-Inverter-Transformer\/dp\/B09NLMVXMZ\/ref=sr_1_3?keywords=5v%2Bpower%2Bsupply%2B3a&amp;qid=1703170698&amp;sr=8-3&amp;th=1\">5 Volt Power Supply for the NeoPixels<\/a><\/li><li><a href=\"https:\/\/www.amazon.com\/Fermerry-Silicone-Stranded-Electronic-Automotive\/dp\/B089CRKSNN\/ref=pd_ci_mcx_pspc_dp_d_1_i_2?pd_rd_w=DMKrp&amp;content-id=amzn1.sym.bc4de2ff-b0aa-42e3-8155-80ce8b46b9f3&amp;pf_rd_p=bc4de2ff-b0aa-42e3-8155-80ce8b46b9f3&amp;pf_rd_r=J95DXR56VH9N01K2AFJF&amp;pd_rd_wg=bZHKC&amp;pd_rd_r=87cf84ac-e6b6-4907-a6f8-d095c3ac5671&amp;pd_rd_i=B089CRKSNN&amp;th=1\" data-type=\"link\" data-id=\"https:\/\/www.amazon.com\/Fermerry-Silicone-Stranded-Electronic-Automotive\/dp\/B089CRKSNN\/ref=pd_ci_mcx_pspc_dp_d_1_i_2?pd_rd_w=DMKrp&amp;content-id=amzn1.sym.bc4de2ff-b0aa-42e3-8155-80ce8b46b9f3&amp;pf_rd_p=bc4de2ff-b0aa-42e3-8155-80ce8b46b9f3&amp;pf_rd_r=J95DXR56VH9N01K2AFJF&amp;pd_rd_wg=bZHKC&amp;pd_rd_r=87cf84ac-e6b6-4907-a6f8-d095c3ac5671&amp;pd_rd_i=B089CRKSNN&amp;th=1\">Silicon wire kit<\/a><\/li><\/ul><\/p>\n\n\n\n<p>You can download the code on my <a href=\"https:\/\/github.com\/lawilmoth\/Christmas\/\">GitHub<\/a>.<\/p>\n<\/div><\/div>\n\n\n\n<p>We started by installing the Adafruit NeoPixel and Blinka libraries from the terminal. You may need to install pip3, but the terminal will show you the command you need to download pip if it fails.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel\nsudo python3 -m pip install --force-reinstall adafruit-blinka<\/code><\/pre>\n\n\n\n<div class=\"wp-block-media-text has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 39%\"><div class=\"wp-block-media-text__content\">\n<p>Then we followed the <a href=\"https:\/\/tutorials-raspberrypi.com\/raspberry-pi-ultrasonic-sensor-hc-sr04\/\" data-type=\"link\" data-id=\"https:\/\/tutorials-raspberrypi.com\/raspberry-pi-ultrasonic-sensor-hc-sr04\/\">tutorial here<\/a> in order to get the distance sensor working. We used the same pins and wiring as they did in the picture. <\/p>\n\n\n\n<p>We also followed this <a href=\"https:\/\/learn.adafruit.com\/neopixels-on-raspberry-pi\/raspberry-pi-wiring\" data-type=\"link\" data-id=\"https:\/\/learn.adafruit.com\/neopixels-on-raspberry-pi\/raspberry-pi-wiring\">wiring diagram<\/a> from Adafruit with the external power supply and the diode to make sure we didn&#8217;t damage the LEDs. We read the <a href=\"https:\/\/learn.adafruit.com\/neopixels-on-raspberry-pi\/python-usage\" data-type=\"link\" data-id=\"https:\/\/learn.adafruit.com\/neopixels-on-raspberry-pi\/python-usage\">documentation<\/a> from Adafruit to see how to program the LEDs on the led strip. It is well done and easy to follow. The only problem that we ran in to was the pi couldn&#8217;t find the packages we installed if we ran sudo python3 christmas.py, but worked if we added -E to the command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#This failed to load the adafruit libraries\nsudo python3 christmas.py\n#This worked\nsudo -E python3 christmas.py<\/code><\/pre>\n\n\n\n<p>We then combined the code from the two projects so if you were within 40 centimeters, the lights would trigger a light sequence. <\/p>\n\n\n\n<p>To finalize the project, we made it so when the sensor is waiting, the lights switch between green and red. When someone gets close, we cycle through white lights, then pulse red or green randomly. <\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-6-768x1024.png\" alt=\"\" class=\"wp-image-112 size-full\" srcset=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-6-768x1024.png 768w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-6-225x300.png 225w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-6-1152x1536.png 1152w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/image-6.png 1440w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-media-text is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/1000005871-768x1024.jpg\" alt=\"\" class=\"wp-image-113 size-full\" srcset=\"https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/1000005871-768x1024.jpg 768w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/1000005871-225x300.jpg 225w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/1000005871-1152x1536.jpg 1152w, https:\/\/theroyalscode.com\/ehs\/wp-content\/uploads\/2023\/12\/1000005871-scaled.jpg 1920w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>Once students had things wired correctly, they soldered the wires to the distance sensor, and we enclosed it in the 3D printed case and attached it to the door with a magnet. This was their first time soldering, and I think they did a nice job. <\/p>\n\n\n\n<p>We then ran the program over an ssh connection so we didn&#8217;t have to get hook a monitor up to the pi everytime we wanted to start the program.<\/p>\n\n\n\n<p>To improve this project, I would like to refactor the code, and learn about chrono tasks so the program would start automatically at the start of the school day.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Have you been naughty or nice this year? This is usually a question that torments children and they have to wait until Christmas morning to find the answer. With our state of the art Sant-a-Scanner, we can say with scientific certainty if you are on the naughty or nice list in under a minute! I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":109,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9,8],"tags":[],"class_list":["post-106","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hardware","category-python"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":4,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/posts\/106\/revisions\/119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/media\/109"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/ehs\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}