In this paper, we developed a simply designed detection method for logic gates by using aptamers, cetyltrimethyl ammonium bromide, together with melamine and cyromazine to control the aggregation and dispersion of gold nanoparticles (AuNPs). First, either melamine or cyromazine can induce the aggregation of AuNPs, supporting an OR gate to detect whether they were present or not. Second, based on the fact that aptamer T31 can specifically bind with melamine, preventing the aggregation of AuNPs, an improved INHIBIT gate was also fabricated to find whether there was melamine. It has a detection limit of 0.12 ppm by the naked eye for the detection of melamine, and the limit of detection (LOD) by spectrophotometer is 2.2 ppb. Third, with the adsorption of aptamer Tcy1 on AuNPs and the strong coordination of Tcy1 with cyromazine, the addition of cyromazine and CTAB immediately resulted in the aggregation of AuNPs, giving rise to an AND gate. This gate has a detection limit of 0.17 ppm by the naked eye and the limit of detection (LOD) is 9.0 ppb by spectrophotometer. The system provided a good platform for the development of functional logic systems.